|1/2-2/3|+|2/3-3/4|+|3/4-4/5|+.......+|8/9-9/10|的结果

来源:百度知道 编辑:UC知道 时间:2024/05/15 06:40:19
我需要过程和结果.
我要的是计算过程,越简单越好

计算过程~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|1/2-2/3|+|2/3-3/4|+|3/4-4/5|+.......+|8/9-9/10|

=2/3-1/2+3/4-3/2+5/4-3/4+……9/10-8/9
=9/10-1/2
=4/10
=0.4

*****************************************

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
float f1=1.0,f2=2.0;
float sum=fabs(f1/f2-f2/(f2+1));
for(int i=2;i<9;i++)
{
f1=f2;
f2=f2+1;
sum=sum+fabs(f1/f2-f2/(f2+1));
}
cout<<"sum="<<sum<<endl;
}

***************************************

sum=0.4
Press any key to continue

#include <stdio.h>
#include <math.h>
#include <iostream.h>

float doit(int n)
{
if (n == 1)
{
return fabs(float(1)/float(2)-float(2)/float(3));
}
else
{
return ( fabs(float(n)/float(n+1)-